<html>
<head>
    <meta charset="UTF-8"/>
    <title>年级总成绩</title>
    <script src="js/jquery-3.5.0.js"></script>
    <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>

    <script src="Vue/Vue.js"></script>
    <script src="Vue/axios.js"></script>
</head>
<body>
<div id="app">
    年级：<select v-model="grade">
    <option v-for='grade in grades' :value="grade.gaId">{{grade.gradeType}}</option>
</select>
    授予教师年级主任权限:<select v-model="teacher">
    <option v-for="teacher in allTeachers" :value="teacher.tcId">{{teacher.name}}</option>
</select>

    <button type="button" @click="setGradeDean">确认</button>
    <br/>

    <script>

        var storage = window.localStorage;
        var token = storage.getItem("token");
        var refreshToken = storage.getItem("refreshToken");


        new Vue({

            el: "#app",
            data: {
                grade: "高一",
                grades: [],
                allTeachers:[],
                teacher:""

            },
            mounted() {
                axios.get(
                    "/principal/gradeDean/allTeacher/", {
                        headers: {
                            "token": token,
                            "refreshToken": refreshToken
                        }
                    }
                ).then(res => {

                    if (res.data.code == 200) {
                        console.log(res.data)
                        this.allTeachers=res.data.data
                    } else if (res.data.code == 500) {
                        console.log("权限不够")
                        $("#app").html("无权限访问")
                    } else if (res.data.code == 302) {
                        window.parent.location.href = "login.html";
                    }

                })

                axios.get(
                    "/principal/gradeDean/allGrade/", {
                        headers: {
                            "token": token,
                            "refreshToken": refreshToken
                        }
                    }
                ).then(res => {

                    if (res.data.code == 200) {
                        console.log(res.data)
                        this.grades=res.data.data
                    } else if (res.data.code == 500) {
                        console.log("权限不够")
                        $("#app").html("无权限访问")
                    } else if (res.data.code == 302) {
                        window.parent.location.href = "login.html";
                    }

                })
            },
            methods: {
                setGradeDean: function () {
                    if(this.teacher !=""){

                        var params = new URLSearchParams();
                        params.append("gaId", this.grade);
                        params.append("tcId", this.teacher);
                        axios.post(
                            "/principal/gradeDean/setGradeDean/",
                            params, {
                                headers: {
                                    "token": token,
                                    "refreshToken": refreshToken
                                }
                            }
                        ).then(res => {

                            if (res.data.code == 200) {
                                console.log(res.data)
                                alert("授予年级主任权限成功")
                            } else if (res.data.code == 500) {
                                console.log("权限不够")
                                $("#app").html("无权限访问")
                            } else if (res.data.code == 302) {
                                window.parent.location.href = "login.html";
                            }

                        })

                    }
                },

            }

        })

    </script>
</div>